<?php
session_start();
include 'inc/db_connect.php';
?>

<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>发邮件</title>
<link rel="stylesheet" type="text/css" href="css/view.css" media="all">
<script type="text/javascript" src="js/view.js"></script>
<!--script type="text/javascript" src="js/calendar.js"></script-->
</head>
<body id="main_body" >

<?php
  include 'inc/gen_header.php';
  gen_header('Mail | <a href=".">Query</a> | <a href=task.php>Task</a> | <a href=wlog.php>Wlog</a>');
?>


<?php
if(isset($_SESSION['logged'])) {
  if(isset($_POST['submit'])) {
    $to = "penglong@sgepri.sgcc.com.cn,gongchm@gmail.com,dingxuetian@sgepri.sgcc.com.cn";
    $subject = $_POST['subject'];
    $message = $_POST['message'];

    $from = "";
    
    $sql = "select email from user_info where id = ".$_SESSION['user_id'];
    $query = mysql_query($sql);
    $num = mysql_num_rows($query);
    if($num > 0) {
      $row = mysql_fetch_array($query);
      $from = $_SESSION['name']."<".$row['email'].">";
    }
    
    $headers = "From: $from "."\r\n"."Reply-To: $from". "\r\n";
    $headers .= "Content-type: text/plain;charset=utf-8" ."\r\n";
    mail($to,$subject,$message,$headers);
    echo "<center>邮件已发送。</center>";
}


?>
	<!--img id="top" src="images/top.png" alt=""-->
	<div id="form_container">
	
		<h1><a>发邮件</a></h1>
		<form id="mail" class="appnitro"  method="post" >
					<div class="form_description">
			<h2>发邮件</h2>
			<p>发邮件给系统管理员</p>
		</div>						
			<ul >
			
					<li id="li_1" >
		<label class="description" for="element_1">主题 </label>
		<div>
			<input id="subject" name="subject" 
			class="element text medium" type="text" maxlength="255"
			 value="关于qlog.me的反馈"/> 
		</div> 
		</li>		<li id="li_2" >
		<label class="description" for="element_2">邮件内容 </label>
		<div>
			<textarea id="message" name="message"
			 class="element textarea medium"></textarea> 
		</div> 
		</li>
		<li class="buttons">
		  <button id="submit" name="submit" class="button_text" type="submit" >
		    发送
		  </button>
		</li>
			</ul>
		</form>	
	</div>
	<!--img id="bottom" src="images/bottom.png" alt=""-->

<?php
} else {
  echo '未登录';
}
?>	
	</body>
</html>